package com.kpijavatraining6.module2.actionTools;

import com.kpijavatraining6.module2.sessionTools.History;

/**
 * Created with IntelliJ IDEA.
 * User: Vladislav
 * Date: 29.10.13
 * Time: 15:35
 * To change this template use File | Settings | File Templates.
 * 31.10.13 cripples added for user to be able to create file
 */
public class UserAction {
    private History history;
    private String userName;

    public final String EXIT = "b";
    public final String UNDO = "u";
    public final String FORWARD = "n";

    public UserAction(History newHistory, String user) {
        history = newHistory;
        userName = user;
    }
    //empty constructor for extended class
    public UserAction(){

    }
    public void newAction(String action) {
    	if(action.equals(UNDO)) {
            history.rollBack();
        }
        if(action.equals(FORWARD)) {
            history.goForward();
        }
        if(action.equals(EXIT)) {
        	        	
        	
            Saver newUser = new Saver(userName);
            newUser.saveHistory(history);
            System.exit(0);
        }
    }
   	public boolean isNewAction(String action) {
        if(action.equals(EXIT)||action.equals(UNDO)||action.equals(FORWARD)) {
            return true;
        } else {
            return false;
        }
    }
}
